<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>


    <div></div>

    <img src="" alt="">


    <script>


        const oDiv = document.querySelector('div') ;
        
        prop(oDiv , 'id' , 'box') ;

        prop(oDiv , 'id' , '') ;

        const id = prop(oDiv , 'id') ;
        console.log(id);


        attr(oDiv,'index',3) ;


        function prop(ele , name , content) {
            // 自有属性
            if(arguments.length === 2) {
                return ele[name]
            } else {
              
                // oDiv.id = 'box'
                ele[name] = content
            }
        }



        function attr(ele , name , content) {
            if(arguments.length === 2) {
                return ele.getAttribute(name) ;
            } else {
                ele.setAttribute(name , content)
            }
        }

    </script>
    
</body>
</html>